package cst.a722wr.zyfypt_722wr.model;

import java.util.List;

import  cst.a722wr.zyfypt_722wr.Bean.FocusResult;
import  cst.a722wr.zyfypt_722wr.Bean.UserBean;
import  cst.a722wr.zyfypt_722wr.iface.FocusListListener;
import  cst.a722wr.zyfypt_722wr.iface.FocusListService;
import  cst.a722wr.zyfypt_722wr.iface.FocusListiface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class FocusListModel<T>  implements FocusListiface{

    private Retrofit retrofit;
    private String BASEURL = "http://amicool.neusoft.edu.cn/";

    public FocusListModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getFocusUserList(String mod, int page, String sessionID, final FocusListListener listener) {
        final FocusListService  service = retrofit.create(FocusListService.class);
        Call<List<FocusResult<UserBean>>> call = service.getFocusUserList(mod, page, sessionID);
        call.enqueue(new Callback<List<FocusResult<UserBean>>>() {
            @Override
            public void onResponse(Call<List<FocusResult<UserBean>>> call, Response<List<FocusResult<UserBean>>> response) {
                if(response.isSuccessful() && response!=null) {
                    listener.onResponse(response.body());
                } else{
                    listener.onFail("onresponse fail");
                }
            }
            @Override
            public void onFailure(Call<List<FocusResult<UserBean>>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
